package com.zuihai.app.mvp.ui.activity.detail;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

import com.blankj.utilcode.util.LogUtils;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.zuihai.app.R;
import com.zuihai.app.mvp.constant.DetailConstant;
import com.zuihai.app.mvp.model.entity.Detail;
import com.zuihai.app.mvp.model.entity.PinglunContent;


import org.simple.eventbus.Subscriber;

/**
 * Created by Administrator on 2017/5/10 0010.
 * 详情页容器
 */

public class DetailContainerActivity extends BaseActivity {

    private int mDetailType;
    private String mDetailId;
    private int mCommodityType;
    private String mHeadlineType;
    private String mUrl;
    private String mCoverUrl;
    private PinglunContent pinglunContent;
    private boolean isDraft=false;
    private String huifuId;

    private String commentId;

    public static void launchComment(Context context,String commentId){
        Intent intent = new Intent(context, DetailContainerActivity.class);
        intent.putExtra(DetailConstant.COMMENT_TYPE, commentId);
        context.startActivity(intent);
    }


    public static void launchActivityUrl(Context context, int type, String detailId, String url, String mCoverUrl){
        Intent intent = new Intent(context, DetailContainerActivity.class);
        intent.putExtra(DetailConstant.DETAIL_TYPE, type);
        intent.putExtra(DetailConstant.EXTRA_ID, detailId);
        intent.putExtra(DetailConstant.EXTRA_VIDEO_URL,url);
        intent.putExtra(DetailConstant.EXTRA_VIDEO_COVER_URL,mCoverUrl);
        context.startActivity(intent);
    }
    public static void launchActivity(Context context, int type, String detailId){
        Intent intent = new Intent(context, DetailContainerActivity.class);
        intent.putExtra(DetailConstant.DETAIL_TYPE, type);
        intent.putExtra(DetailConstant.EXTRA_ID, detailId);
        context.startActivity(intent);
    }

    public static void launchActivity(Context context, int type, String detailId,Boolean isDraft){
        Intent intent = new Intent(context, DetailContainerActivity.class);
        intent.putExtra(DetailConstant.DETAIL_TYPE, type);
        intent.putExtra(DetailConstant.EXTRA_ID, detailId);
        intent.putExtra(DetailConstant.EXTRA_IS_DRAFT,isDraft);
        context.startActivity(intent);
    }

    /**
     * 动态栏目更新前可用 headLineType  int -> String
     * @param context
     * @param type
     * @param headLineType
     * @param detailId
     */
    public static void launchActivity(Context context, int type, String headLineType,String detailId){
        Intent intent = new Intent(context, DetailContainerActivity.class);
        intent.putExtra(DetailConstant.DETAIL_TYPE, type);
        intent.putExtra(DetailConstant.EXTRA_ID, detailId);
        intent.putExtra(DetailConstant.EXTRA_HEADLINE_TYPE,headLineType);
        context.startActivity(intent);
    }
    public static void launchActivity(Context context, int type, String headLineType,String detailId,Boolean isDraft){
        Intent intent = new Intent(context, DetailContainerActivity.class);
        intent.putExtra(DetailConstant.DETAIL_TYPE, type);
        intent.putExtra(DetailConstant.EXTRA_ID, detailId);
        intent.putExtra(DetailConstant.EXTRA_HEADLINE_TYPE,headLineType);
        intent.putExtra(DetailConstant.EXTRA_IS_DRAFT,isDraft);
        context.startActivity(intent);
    }

    public static void launchActivity(Context context, int type, int headLineType,String detailId,Boolean isDraft){
        Intent intent = new Intent(context, DetailContainerActivity.class);
        intent.putExtra(DetailConstant.DETAIL_TYPE, type);
        intent.putExtra(DetailConstant.EXTRA_ID, detailId);
        intent.putExtra(DetailConstant.EXTRA_HEADLINE_TYPE,headLineType);
        intent.putExtra(DetailConstant.EXTRA_IS_DRAFT,isDraft);
        context.startActivity(intent);
    }
   public void launchActivity(Context context, int type, int headLineType, String detailId, Detail.Comment mComment){
        Intent intent = new Intent(context, DetailContainerActivity.class);
        intent.putExtra(DetailConstant.DETAIL_TYPE, type);
        intent.putExtra(DetailConstant.EXTRA_ID, detailId);
        intent.putExtra(DetailConstant.EXTRA_HEADLINE_TYPE,headLineType);
        Bundle mBundle = new Bundle();
        mBundle.setClassLoader(Detail.Favour.class.getClassLoader());
        mBundle.putParcelable(DetailConstant.EXTRA_COMMENT_TYPE, mComment);
        intent.putExtras(mBundle);
        context.startActivity(intent);
    }

    public static void launchActivity(Context context, int type, int headLineType, String detailId, String huifuId){
        Intent intent = new Intent(context, DetailContainerActivity.class);
        intent.putExtra(DetailConstant.DETAIL_TYPE, type);
        intent.putExtra(DetailConstant.EXTRA_ID, detailId);
        intent.putExtra(DetailConstant.EXTRA_HEADLINE_TYPE,headLineType);
        intent.putExtra(DetailConstant.EXTRA_HUIFU_ID,huifuId);

        context.startActivity(intent);
    }

    public static void launchActivity(Context context, int type, String detailId, int commodityType){
        Intent intent = new Intent(context, DetailContainerActivity.class);
        intent.putExtra(DetailConstant.DETAIL_TYPE, type);
        intent.putExtra(DetailConstant.EXTRA_ID, detailId);
        intent.putExtra(DetailConstant.EXTRA_COMMODITY_TYPE, commodityType);
        context.startActivity(intent);
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
    }

    @Subscriber( tag = "abcdefg" )
    public void detailComment(String comment) {
        LogUtils.e("----comment---- : ");
    }

    @Override
    protected View initView() {
        View view = LayoutInflater.from(this).inflate(R.layout.activity_fragment_container, null, false);
        return view;
    }

    @Override
    protected void initData() {
        setSwipeBackEnable(true);
        mCoverUrl=getIntent().getStringExtra(DetailConstant.EXTRA_VIDEO_COVER_URL);
        mUrl=getIntent().getStringExtra(DetailConstant.EXTRA_VIDEO_URL);
        mHeadlineType=getIntent().getStringExtra(DetailConstant.EXTRA_HEADLINE_TYPE);
        mDetailType = getIntent().getIntExtra(DetailConstant.DETAIL_TYPE, -1);
        mDetailId = getIntent().getStringExtra(DetailConstant.EXTRA_ID);
        mCommodityType = getIntent().getIntExtra(DetailConstant.EXTRA_COMMODITY_TYPE, -1);
        isDraft= getIntent().getBooleanExtra(DetailConstant.EXTRA_IS_DRAFT,false);
        huifuId=getIntent().getStringExtra(DetailConstant.EXTRA_HUIFU_ID);

        //跳转评论专用
        commentId=getIntent().getStringExtra(DetailConstant.COMMENT_TYPE);
        if (commentId!=null){

        }
        Intent intent = getIntent();
        Bundle mBundle = intent.getExtras();
        pinglunContent = (PinglunContent) mBundle.getSerializable(DetailConstant.EXTRA_COMMENT_TYPE);

        switch (mDetailType){
            case DetailConstant.HEADLINE_TYPE:
                loadRootFragment(R.id.content_layout, DetailHeadlineFragment.newInstance(mDetailId,mHeadlineType,huifuId,isDraft));
                break;

        }
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

    }

    public void  onSetSwipeBackEnable(boolean yn){
        setSwipeBackEnable(yn);
    }


    public PinglunContent  getPinglunContent(){
        return pinglunContent;
    }

}